package com.sun;

import javax.swing.plaf.metal.MetalIconFactory;
import java.math.BigDecimal;

/**
 * https://leetcode.cn/problems/container-with-most-water/
 *
 */
public class Test11盛最多水的容器 {
    public static void main(String[] args) {
        BigDecimal bigDecimal1 = new BigDecimal(0.1);
        System.out.println(bigDecimal1);
        BigDecimal bigDecimal2 = BigDecimal.valueOf(0.1);
        System.out.println(bigDecimal2);
        int[] height = new int[]{2,3,4,5,18,17,6};
        int area = maxArea2(height);
        System.out.println(area);
    }

    /**
     * 方法1：自己,暴力循环
     */
    public static int maxArea1(int[] height){
        int area = 0;
        for (int i = 0; i < height.length; i++) {
            for (int j = i+1; j < height.length; j++) {
                int len = j - i;
                int high = Math.min(height[i],height[j]);
                area = Math.max(area,high * len);
            }
        }
        return area;
    }

    /**
     * 方法2：双指针
     */
    public static int maxArea2(int[] height){
        int left = 0;
        int right = height.length -1;
        int area = 0;
        while (left < right){
            area = Math.max(area,Math.min(height[left],height[right])*(right - left));
            if (height[left] >= height[right]){
                right --;
            }else {
                left ++;
            }
        }
        return area;
    }
}
